Improve the error message for missing path overrides
authorAlex Crichton <alex@alexcrichton.com>
Fri, 11 Mar 2016 20:05:58 +0000 (12:05 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 11 Mar 2016 20:05:58 +0000 (12:05 -0800)
Closes #2457

src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_read_manifest.rs
tests/test_cargo_compile_path_deps.rs

index 1ac2298858132ecc73d613b6fd511b5ededffe08..ad82d4f773e002888ad7cd2fae307db68e45722b 100644 (file)
@@ -34,7 +34,7 @@ use core::resolver::{Method, Resolve};
 use ops::{self, BuildOutput, ExecEngine};
 use sources::PathSource;
 use util::config::Config;
-use util::{CargoResult, profile};
+use util::{CargoResult, profile, human, ChainError};
 
 /// Contains information about how a package should be compiled.
 pub struct CompileOptions<'a> {
@@ -393,17 +393,21 @@ fn add_overrides<'a>(registry: &mut PackageRegistry<'a>,
         // The path listed next to the string is the config file in which the
         // key was located, so we want to pop off the `.cargo/config` component
         // to get the directory containing the `.cargo` folder.
-        p.parent().unwrap().parent().unwrap().join(s)
-    }).filter(|p| {
+        (p.parent().unwrap().parent().unwrap().join(s), p)
+    }).filter(|&(ref p, _)| {
         // Make sure we don't override the local package, even if it's in the
         // list of override paths.
         cur_path != &**p
     });
 
-    for path in paths {
+    for (path, definition) in paths {
         let id = try!(SourceId::for_path(&path));
         let mut source = PathSource::new_recursive(&path, &id, config);
-        try!(source.update());
+        try!(source.update().chain_error(|| {
+            human(format!("failed to update path override `{}` \
+                           (defined in `{}`)", path.display(),
+                          definition.display()))
+        }));
         registry.add_override(&id, Box::new(source));
     }
     Ok(())
index ddaace3421fa35c876bcdce3d70efbc994d7c49e..445a356c42682273ae6b407b8794208e9cc0f3d2 100644 (file)
@@ -87,7 +87,11 @@ fn walk(path: &Path, callback: &mut FnMut(&Path) -> CargoResult<bool>)
         Err(ref e) if e.kind() == io::ErrorKind::PermissionDenied => {
             return Ok(())
         }
-        Err(e) => return Err(From::from(e)),
+        Err(e) => {
+            return Err(human(e)).chain_error(|| {
+                human(format!("failed to read directory `{}`", path.display()))
+            })
+        }
     };
     for dir in dirs {
         let dir = try!(dir);
index 5cd97d301fdbaace8835ea22628511176591130b..58dbf43696d5dc0c2b9f1108a4a429982fb56730 100644 (file)
@@ -838,3 +838,30 @@ test!(override_and_depend {
 {compiling} b v0.5.0 ([..])
 ", compiling = COMPILING)));
 });
+
+test!(missing_path_dependency {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "a"
+            version = "0.5.0"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file(".cargo/config", r#"
+            paths = ["../whoa-this-does-not-exist"]
+        "#);
+    p.build();
+    assert_that(p.cargo("build"),
+                execs().with_status(101)
+                       .with_stderr("\
+failed to update path override `[..]../whoa-this-does-not-exist` \
+(defined in `[..]`)
+
+Caused by:
+  failed to read directory `[..]`
+
+Caused by:
+  [..] (os error [..])
+"));
+});